package license

import (
	"context"

	v1 "gitee.com/liangziyisheng/caas-platform-mc/api/license/v1"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/consts"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/service"
	"gitee.com/liangziyisheng/caas-platform-mc/utility/utils"
)

func (c *ControllerV1) Add(ctx context.Context, req *v1.AddReq) (res *v1.AddRes, err error) {
	// 获取tenant code
	// tenantCode := ctx.Value(consts.TokenClaims.TenantCode).(string)
	in := &v1.AddInput{}
	utils.CopyStruc(*req, in)
	// in.TenantCode = tenantCode
	in.Status = consts.LicenseStatus[0].Value
	out, err := service.License().Add(ctx, in)
	if err != nil {
		return nil, err
	}
	return &v1.AddRes{
		Id: out.Id,
	}, nil
}
